package com.bwie.auth.controller;

import com.bwie.auth.service.AuthService;
import com.bwie.common.doamin.dto.LoginDTO;
import com.bwie.common.doamin.dto.RegisterDTO;
import com.bwie.common.doamin.vo.LoginVO;
import com.bwie.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 鉴权控制层
 *
 * @author <a href="mailto:2943147140@qq.com">刘洋朔</a>
 * @version 1.0
 * @description: 鉴权控制层
 * @date 2025/9/9 10:38
 */
@RestController
@CrossOrigin
public class AuthController {
    /**
     * 鉴权业务层
     */
    @Autowired
    private AuthService authService;

    /**
     * 用户登录
     * @param loginDTO
     * @return LoginVO
     */
    @PostMapping("login")
    public Result<LoginVO> login(@RequestBody @Valid LoginDTO loginDTO){
        LoginVO loginVO = authService.login(loginDTO);
        return Result.success(loginVO);
    }


    /**
     * 获取手机号发送验证码
     * @param phone
     * @return void
     */
    @GetMapping("sendCode/{phone}")
    public Result<Void> sendCode(@PathVariable("phone") String phone){
        authService.sendCode(phone);
        return Result.success();
    }


    /**
     * 用户注册
     * @param registerDTO
     * @return void
     */
    @PostMapping("register")
    public Result<LoginVO> register(@RequestBody @Valid RegisterDTO registerDTO){
        authService.register(registerDTO);
        return Result.success();
    }


}
